<script setup lang="ts">
import type { Goods } from '@/types'
import { http } from '@/utils/request'
import GoodsItem from '@/views/category/components/GoodsItem.vue'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'

interface Props {
  type: 1 | 2 | 3
}
const props = withDefaults(defineProps<Props>(), {
  type: 1
})

const hotListTitle = {
  1: '24小时热销榜',
  2: '周热销榜',
  3: '总热销榜'
}
type GoodsList = Goods[]
const goodsList = ref<GoodsList>([])
const route = useRoute()
onMounted(async () => {
  const res = await http<GoodsList>('GET', '/goods/hot', {
    id: route.params.id,
    type: props.type
  })
  goodsList.value = res.data.result
})
</script>

<template>
  <div class="goods-hot">
    <h3>{{ hotListTitle[type] }}</h3>
    <div class="goods-list">
      <!-- 商品区块 -->
      <GoodsItem v-for="item in goodsList" :key="item.id" :goods-item="item" />
    </div>
  </div>
</template>

<style lang="less" scoped>
.goods-hot {
  margin-bottom: 20px;
  background-color: #fff;

  h3 {
    margin-bottom: 10px;
    padding-left: 25px;
    height: 70px;
    color: #fff;
    font-size: 18px;
    font-weight: normal;
    line-height: 70px;
    background: @helpColor;
  }

  .goods-list {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
